#!/usr/bin/env python
# encoding: utf-8
"""
#-------------------------------------------------------------------#
#                   CONFIDENTIAL --- CUSTOM STUDIOS                 #     
#-------------------------------------------------------------------#
#                                                                   #
#                   @Project Name : 全球法律在线项目                #
#                                                                   #
#                   @File Name    : textfunction.py                      #
#                                                                   #
#                   @Programmer   : 李建                            #
#                                                                   #  
#                   @Start Date   : 2020-11-27 9:43                 #
#                                                                   #
#                   @Last Update  : 2020-11-27 9:43                 #
#                                                                   #
#-------------------------------------------------------------------#
# Classes:该类用于测试函数                                                          #
#                                                                   #
#-------------------------------------------------------------------#
"""
import base64
import datetime
import hashlib
import os
import re
import shutil

import PyPDF2
import requests
import pythainlp


def pic_ocr(pic_adr):

    # 以二进制方式打开图片文件
    with open(pic_adr, 'rb') as f:
        img = base64.b64encode(f.read())
    return img


def main():
    # SYSIDS = []
    # with open("D:\新建文本文档.txt", 'r+', encoding='utf-8') as f:
    #     for linen in f:  # 按行读取文件
    #         line = linen.replace('\n', '')
    #         SYSID = str(hashlib.md5(line.encode('utf-8')).hexdigest())
    #         SYSIDS.append(SYSID)
    # wrt = ('\n').join(SYSIDS)
    # with open("sysid.txt", 'a+', encoding='utf-8') as w:
    #     w.write(str(wrt) + '\n')
    pdf_dir = os.path.join(r"E:\工作记录\工作内容\“一带一路”项目\各国专家提供的法律资源资料\缅甸\西政老师提供\导入\案例")
    pdf_new_dir = os.path.join(r"E:\工作记录\工作内容\“一带一路”项目\各国专家提供的法律资源资料\缅甸\西政老师提供\导入\Case-wu")
    with open(r"D:\logErro.txt", 'r+', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            pdf_name = os.path.split(line)[1]
            pdf_name = pdf_name.rstrip(' \n')
            pdf_list = os.listdir(pdf_dir)
            if pdf_name in pdf_list:
                shutil.copyfile(os.path.join(pdf_dir,pdf_name), os.path.join(pdf_new_dir,pdf_name))
            else:
                print(line)
    detailUrl = "4. ________________________________ ____________"
    SYS_FLD_DIGITFILENAME = 'f' + str(hashlib.md5(detailUrl.encode('utf-8')).hexdigest())
    print(str(hashlib.md5(detailUrl.encode('utf-8')).hexdigest()))
    print(SYS_FLD_DIGITFILENAME)
    text = "ประกาศ เรื่อง การขยายระยะเวลาการประกาศสถานการณ์ฉุกเฉินที่มีความ(ร้ายแรงในเขตท้องที่) (จังหวัดนราธิวาส) จังหวัดปัตตานี และจังหวัดยะลา"
    word = text.replace("(", "")
    word = word.replace(")", "")
    lista = ["a", "dgs", "sdgsd", "asdgs"]
    listb = ["a", "sgs", "sdgsdgd", "asdgs"]
    listc = lista + listb
    listd = list(set(lista + listb))
    with open("D:\Default.txt", 'a+', encoding='gbk') as f:
        f.seek(0)
        lines = f.readlines()
        originaldict = {}
        for line in lines:
            line = line.rstrip("\n")
            key_list = line.split("	")
            key = key_list[0]
            values = []
            for key_str in key_list[1:]:
                key_str = key_str.rstrip(";")
                value_list = key_str.split(";")
                for value in value_list:
                    values.append(value)
            originaldict[key] = values

    date_now = datetime.date.today()
    date_yes = date_now + datetime.timedelta(days=-1)
    # str = "e2a8c49f2c00114d96b1f1e07093b4ecc.xml"
    # a= str.rstrip("c.xml")
    # print(a)
    # print(int(105/10))
    DEFAULT_REQUEST_HEADERS = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'en',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36'
    }
    res = requests.get("http://www.kehakiman.gov.my/ms", headers=DEFAULT_REQUEST_HEADERS, verify=False)
    file = open(r"E:\PP Indonesia\erro.txt")
    file_path = r"E:\PP Indonesia"
    mu_path = r"D:\PDF\Law\Indonesia\peraturan\perpem"
    for line in file:
        line = line.replace("\n", "")
        ISFind = False
        for root, dirs, files in os.walk(file_path, topdown=False):
            if line in files:
                ISFind = True
                new_name = "f" + str(hashlib.md5(line.encode('utf-8')).hexdigest()) + ".pdf"
                try:
                    os.rename(os.path.join(root, line), os.path.join(root, new_name))
                    shutil.copy(os.path.join(root, new_name), os.path.join(mu_path, new_name))
                except Exception as e:
                    with open("cuowu.txt", "a", encoding="utf-8") as f:
                        f.write(line + "\n")
                    print(str(e))
                break
        if not ISFind:
            with open("notfind.txt", "a", encoding="utf-8") as g:
                g.write(line + "\n")


    data = "（付给前配偶的）赡养费"
    data = data.lstrip("（")
    key_list = re.split(r"\(", "abuse (people)")
    with open('pdferror.txt', 'a', encoding='utf-8') as f:
        f.write(str(datetime.datetime.now()) + "pdffilepath" + '\n')
    print(str(datetime.datetime.now()) + ":时间函数测试")
    listq = ["1", "24", "324123"]
    strl = ";".join(listq)
    print(strl)
    COUNTRY = {"LAWCOUNTRYXJP": ["Acts", "Subsidiary Legislation"], "LAWOCUNTWG":"asgfa"}
    a= list(COUNTRY.keys())
    path1 = 'D:\GlobalLawFiles'
    path2 = 'case\Indonesia\putusan\Perdata\f00009cb3cbd97475d3997aad812ceda3.pdf'
    pdf_path = os.path.join(path1,path2)
    pdf_path = r'D:\GlobalLawFiles\case\Indonesia\putusan\Perdata\f00009cb3cbd97475d3997aad812ceda3.pdf'
    mb_path = r'D:\GlobalLawFile\case\Indonesia\putusan\Perdata\f00009cb3cbd97475d3997aad812ceda3.pdf'
    state = os.path.exists(pdf_path)


if __name__=='__main__':
    main()
